#coding=utf-8
import sys
reload(sys)

class HtmlOutput(object):
    def __init__(self):
        self.datas = []
        sys.setdefaultencoding('utf-8')
        
    def collect_data(self,data):
        if data is None:
            return
        #self.datas.append(data)
        fileout = open('output.txt','a')
        fileout.write('%s,%s,%s,%s'%(data['url'],data['week_visit'].encode('utf-8'),data['month_visit'].encode('utf-8'),data['all_visit'].encode('utf-8')))
        fileout.write('\n')

    
    def output_html(self):
        fout = open('output.html','w')
        
        fout.write("<html>")
        fout.write("<head>")
        fout.write('<meta charset="utf-8">')
        fout.write("</head>")
        fout.write("<body>")
        fout.write("<table>")
            
        for data in self.datas:
            fout.write("<tr>")
            fout.write("<td>%s</td>" % data['url'])
            fout.write("<td>%s</td>" % data['week_visit'].encode('utf-8'))
            fout.write("<td>%s</td>" % data['month_visit'].encode('utf-8'))
            fout.write("<td>%s</td>" % data['all_visit'].encode('utf-8'))
            fout.write("</tr>")
            
        fout.write("</table>")
        fout.write("</body>")
        fout.write("</html>")
    
    
    
    



